In a regular programming language (i.e: Javascript), you may need try.. catch block in order to :
- Handle Errors
- Increase the fir
try {
doSomething("...")
} catch(error) {
doTheOtherThing("....")
}
Ansible has something similar which is block... rescue
This is an example :
- name: Handle the error
block:
- debug:
msg: 'I execute normally'
- name: i force a failure
command: /bin/false
- debug:
msg: 'I never execute, due to the above task failing, :-('
rescue:
- debug:
msg: 'I caught an error, can do stuff here to fix it, :-)'Where :
- block is an array of tasks
- rescue is an array of tasks as well
- block & rescue are attributes under the big task "Handle the error"